Algorithms for context-free grammar generation